package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class OrderDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "order.db" ;
    private static final int DATABASE_VERSION = 1 ;

    public static final String TABLE_ORDER = "orders" ;
    public static final String ORDER_ID = "id" ;
    public static final String ORDER_LOCAL_ID = "localId" ;
    public static final String ORDER_GOODS_ID = "goodsId" ;
    public static final String ORDER_NUM = "num" ;
    public static final String ORDER_REMARK = "remark" ;
    public static final String ORDER_BUYER = "buyer" ;
    public static final String ORDER_SALES = "sales" ;
    public static final String ORDER_TYPE = "type" ;
    public static final String ORDER_TIME = "time" ;

    private static final String CREATE_TABLE_ORDER = "CREATE TABLE " + TABLE_ORDER + " ( " +
            ORDER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " +
            ORDER_LOCAL_ID + " INT , " +
            ORDER_GOODS_ID + " INT , " +
            ORDER_NUM + " INT , " +
            ORDER_REMARK + " TEXT , " +
            ORDER_BUYER + " TEXT , " +
            ORDER_SALES + " TEXT , " +
            ORDER_TYPE + " TEXT , " +
            ORDER_TIME + " TEXT )" ;

    public OrderDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_ORDER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ORDER);
        onCreate(db);
    }
}
